﻿using Ledict.ConditionExtract.Base;
using Ledict.ConditionExtract.BLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Ledict.ConditionExtract.Frm
{
    public partial class ElementRules : BaseForm
    {
        RegInfoBLL regbll = new RegInfoBLL();
        public string InfoCode { get; set; }

        public ElementRules()
        {
            InitializeComponent();
        }

        private void ElementRules_Load(object sender, EventArgs e)
        {
            dgvRule.AutoGenerateColumns = false;
            dgvRule.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

            DataTable dt = regbll.GetRegexInfoUnit("'EI2001021013120001'");
            if (dt != null && dt.Rows.Count > 0)
                dgvRule.DataSource = dt;
        }

        private void btnSure_Click(object sender, EventArgs e)
        {
            int num = 0;
            int j = 0;
            for (var i = 0; i <= dgvRule.Rows.Count - 1; i++)
            {
                var check = (DataGridViewCheckBoxCell)dgvRule.Rows[i].Cells["check"];
                if (Convert.ToBoolean(check.Value))
                {
                    num++;
                    j = i;
                }
            }
            if (num == 0)
            {
                MessageBox.Show("请选择需要执行的信息单元");
                return;
            }
            if (num > 1)
            {
                MessageBox.Show("只能选择一个执行的信息单元");
                return;
            }
            else
            {
                InfoCode= dgvRule.Rows[j].Cells["Num"].Value.ToString();
            }
            DialogResult = DialogResult.Yes;
            this.Close();
        }
    }
}
